////////////////////////////////////////////////////////////////////////////////
// This file is part of the Mist compiler.                                    //
//                                                                            //
// Copyright (C) 2009 The Mist project                                        //
//                                                                            //
// For a list of contributors, see the COMMITTERS file.                       //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// in the COPYING file. If not, see <http://www.gnu.org/licenses/>.           //
////////////////////////////////////////////////////////////////////////////////

///
/// \file
/// Contains the TypeSpec class.
///

#ifndef TYPESPEC_HPP
#define TYPESPEC_HPP

////////////////////////////////////////////////////////////////////////////////
// Includes                                                                   //
////////////////////////////////////////////////////////////////////////////////

#include "common/ptr.hpp"
#include "nodes.hpp"

////////////////////////////////////////////////////////////////////////////////
// Forward Declarations                                                       //
////////////////////////////////////////////////////////////////////////////////

CLASSES_FROM( CONCRETE_NODES )

////////////////////////////////////////////////////////////////////////////////
// TypeSpec Class                                                             //
////////////////////////////////////////////////////////////////////////////////

/// A complete specification of template types and formal parameter types.
/// Together with a name and scope, a TypeSpec could uniquely identify a
/// function or type declaration.
///
class TypeSpec {
	public:
		
		TypeSpec() {}
		TypeSpec(const vector<wptr<Identifier> >& tts) : templateTypeSpec(tts) {}
		TypeSpec(const vector<wptr<Identifier> >& tts, const vector<wptr<Type> >& fts) : templateTypeSpec(tts), formalTypeSpec(fts) {}
		
		/// The template parameter names. Can as of yet only be types.
		///
		vector<wptr<Identifier> > templateTypeSpec;
		
		/// The formal parameter types, for functions.
		///
		vector<wptr<Type> > formalTypeSpec;
		
		/// \return  true, if \a ref has a type-specification incompatible with this one
		///         false, otherwise
		///
		bool incompatible_with_reference(wptr<Reference> ref) const;
		
		/// Puts TypeSpecs in a total order, for using them as a key in
		/// an associative container.
		///
		class Before {
			public:
				
				bool operator()(const TypeSpec& a, const TypeSpec& b);
		};
};

#endif // TYPESPEC_HPP
